package com.suwish.pc.ui.component.tab;


import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

import javax.swing.Icon;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;

/**
 * 
 * 
 * 
 * @author Min
 *
 */
public class UITab extends JPanel {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private Icon icon = null;
	private String text = null;
	
	private JLabel iconLabel = null;
	private JLabel textLabel = null;
	
	private boolean selected;
	
	private TabPanelUI ui = null;
	
	/**
	 * 
	 * @param icon  图标
	 * @param text 标题
	 * @param toolTip 
	 */
	public UITab(Icon icon, String text){
		setUI(ui = new TabPanelUI());
		this.icon = icon;
		this.text = text;
		setLayout(new GridBagLayout());
		
		iconLabel = new JLabel(icon);
		textLabel = new JLabel(text);
		
		add(iconLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(3, 2, 3, 2), 0, 0));
		add(textLabel, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(3, 2, 3, 10), 0, 0));
//		add(new JLabel(new ImageIcon("D:\\devspase\\android\\JPhoneBridge\\build\\resources\\images\\close_dark.png")), new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(3, 2, 3, 10), 0, 0));

	}
	
	public void addComponent(JComponent comp) {
        add(comp, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(3, 2, 3, 2), 0, 0));
    }
	/**
	 * 
	 * @param title
	 */
	public UITab(String text){
		this(null, text);
	}
	public boolean isSelected() {
		return selected;
	}
	public void setSelected(boolean selected) {
		this.selected = selected;
		ui.setSelected(selected);
		if (selected) {
            textLabel.setFont(textLabel.getFont().deriveFont(Font.BOLD));  
    	    
        }else if (!selected) {
            textLabel.setFont(Font.getFont(Font.DIALOG));
      
        }


        invalidate();
        validate();
        repaint();

        textLabel.invalidate();
        textLabel.validate();
        textLabel.repaint();
	}
	
	
}
